﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

/// <summary>
/// Summary description for LinkTemplate
/// </summary>
public class LinkTemplate : ITemplate
{
    string columnName;

    public LinkTemplate(DataControlRowType type, string columnName)
    {
        //
        // TODO: Add constructor logic here
        //
        this.columnName = columnName;
    }



    #region ITemplate Members

    public void InstantiateIn(Control container)
    {
        Literal lit = new Literal();
        lit.ID = columnName;
        lit.DataBinding +=new EventHandler(Url_DataBinding);
        container.Controls.Add(lit);
    }


    private void Url_DataBinding(Object sender, EventArgs e)
    {
        Literal lit = (Literal)sender;
        GridViewRow row = (GridViewRow)lit.NamingContainer;
        lit.Text = "<a href=\"" + DataBinder.Eval(row.DataItem, lit.ID) + "\">Link</a>";
    }
    #endregion
}
